
package com.epam.android.training;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * File Selector Db.
 * 
 * @author Natallia_Kukharchyk
 */
public class FileSelectorDb {

  private final FileSelectorOpenHelper helper;

  public FileSelectorDb(Context context) {
    helper = new FileSelectorOpenHelper(context);
  }

  public Cursor getFilesCursor() {
    SQLiteDatabase db = helper.getReadableDatabase();
    Cursor cursor = db.query(FileSelectorOpenHelper.TABLE_NAME, null, null, null, null, null,
        FileSelectorOpenHelper.FILE_NAME + " ASC");
    return cursor;
  }

  public boolean insertFile(String fileName) {
    SQLiteDatabase db = helper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(FileSelectorOpenHelper.FILE_NAME, fileName);
    return (db.insert(FileSelectorOpenHelper.TABLE_NAME, null, values) > 0);
  }

  public void close() {
    helper.close();
  }
}
